﻿Imports DevComponents.DotNetBar
Imports quanlydulich.Helpers

Public Class VEKHACHHANG
    Inherits Office2007Form

    ' Event handler is used to transfer data to receiver
    Public Event Handler(ByVal sender As Object, ByVal e As MyEvent)
    Friend WithEvents frmKhachHang As KHACHHANG
    Friend WithEvents frmLoaiVe As LOAIVE

    ' Hidden files are used to store ids 
    Private txtMaKH As DevComponents.DotNetBar.Controls.TextBoxX
    Private txtMaLoaiVe As DevComponents.DotNetBar.Controls.TextBoxX

    Public Sub InitHiddenFields()
        ' Add a new textbox
        txtMaKH = New DevComponents.DotNetBar.Controls.TextBoxX() With { _
         .Name = "txtMaKH", _
         .Text = "" _
        }
        txtMaKH.Visible = False

        ' Add a new textbox
        txtMaLoaiVe = New DevComponents.DotNetBar.Controls.TextBoxX() With { _
         .Name = "txtMaLoaiVe", _
         .Text = "" _
        }
        txtMaLoaiVe.Visible = False
    End Sub
    Private Sub btnChonVLXD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChonVLXD.Click
        frmKhachHang = New KHACHHANG
        frmKhachHang.ShowDialog()
    End Sub

    Private Sub frmKhachHang_Handler(ByVal sender As Object, ByVal e As MyEvent) Handles frmKhachHang.Handler
        Dim eventType = DirectCast(e, MyEvent)
        Dim comp As String() = eventType.Data.Split(New Char() {"#"})

        txtMaKH.Text = comp(0) 'id
        txtKhachHang.Text = comp(1) 'name
    End Sub

    Private Sub btnCapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhat.Click
        If txtMaKH.Text = "" Then
            MessageBoxEx.Show("Vui lòng chọn khách hàng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        If txtMaLoaiVe.Text = "" Then
            MessageBoxEx.Show("Vui lòng chọn loại vé", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        If txtSoGhe.Text = "" Then
            MessageBoxEx.Show("Vui lòng nhập số ghế", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        Close()
        RaiseEvent Handler(Me, New MyEvent(txtMaKH.Text & "#" & txtMaLoaiVe.Text & "#" & txtSoGhe.Text))
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Close()
    End Sub

    Private Sub VEKHACHHANG_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitHiddenFields()
    End Sub

    Private Sub btnChonLoaiVe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChonLoaiVe.Click
        frmLoaiVe = New LOAIVE
        frmLoaiVe.ShowDialog()
    End Sub

    Private Sub frmLoaiVe_Handler(ByVal sender As Object, ByVal e As MyEvent) Handles frmLoaiVe.Handler
        Dim eventType = DirectCast(e, MyEvent)
        Dim comp As String() = eventType.Data.Split(New Char() {"#"})

        txtMaLoaiVe.Text = comp(0) 'id
        txtLoaiVe.Text = comp(1) 'name
    End Sub
End Class